package ke07.pm.template.reihe2;

import java.util.ArrayList;

public class HundredItemBag<T> {

	private ArrayList<T> collec = new ArrayList<T>();
	private int anzahl;

	public int size() {
		anzahl = collec.size();
		return collec.size();
	}

	public T[] toArray() {
		T[] collec2 = (T[]) collec.toArray();

		return collec2;
	}

	public boolean add(T o) {
		if (o == null)
			throw new NullPointerException();
		else if (collec.contains(o)) {
			collec.add(o);
			return true;
		} else
			collec.add(o);
		return false;
	}

	public boolean contains(T obj) {
		T[] array = (T[]) collec.toArray();
		for (int i = 0; i < array.length; i++) {
			if (array[i] == obj) {
				return true;
			}

		}
		return false;

	}

	public boolean remove(Object obj) throws IllegalArgumentException {
		if (obj == null) {
			throw new IllegalArgumentException();
		} else {
			collec.remove(obj);
		}
		if (count(obj) == 0) {
			return true;
		} else {
			return false;
		}
	}

	public int count(Object obj) {
		int counter = 0;
		for (Object o : collec) {
			if (o.equals(obj)) {
				counter++;
			}
		}
		return counter;
	}
}
